package com.xp.code.view;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.xp.code.services.IUnitInfoService;
import com.xp.code.util.XPCodeSession;
import com.xp.code.vo.*;

/**
 * 
 * @author HAHA
 * 
 */
@Controller("unitInfoAction")
@Scope("prototype")
public class UnitInfoAction extends XPInfoAction implements ModelDriven<UnitInfoVO> {

	private Logger loger=Logger.getLogger(UnitInfoAction.class);
	@Resource(name = "unitInfoService")
	private IUnitInfoService unitInfoService;

	private UnitInfoVO unitInfoVO;

	public UnitInfoAction() {

	}

	public UnitInfoVO getModel() {
		unitInfoVO = new UnitInfoVO();
		return unitInfoVO;
	}

	public IUnitInfoService getUnitInfoService() {
		return unitInfoService;
	}

	public void setUnitInfoService(IUnitInfoService unitInfoService) {
		this.unitInfoService = unitInfoService;
	}

	public String addUnitInfos() throws Exception {
		UnitInfoVO vo = unitInfoService.addUnitInfos(unitInfoVO);
		JSONObject jo = JSONObject.fromObject(vo);
		setJsonString(jo.toString());
		return SUCCESS;
	}

	public String parentUnitInfos() throws Exception {
		loger.debug("parentUnitInfos");
		XPCodeSession xpsession=new XPCodeSession();
		List<UnitInfoVO> info=unitInfoService.getParentUnitInfo(xpsession.getUNITID());
		JSONArray ja=JSONArray.fromObject(info);
		setJsonString(ja.toString());
		return SUCCESS;
	}
}
